#define FRAMEWORK_VER_2x
#if !MONODROID
using System;
using System.Drawing;
using System.Reflection;
using System.Windows.Forms;

namespace Devsoft.Utilities
{
	/// <summary>
	/// Summary description for StyleRender.
	/// </summary>
	public class StyleRender
	{
		public StyleRender()
		{
			//
			// TODO: Add constructor logic here
			//
		}

		public const int VERTICAL  = 0;
		public const int HORIZONTAL  = 1;
	
		public static System.Drawing.Color Color3D1 = System.Drawing.Color.FromArgb(0xAC,0xA8,0x99);
		public static System.Drawing.Color Color3D2 = System.Drawing.Color.FromArgb(0xff,0xff,0xff);

        /// <summary>
        /// Sets the double buffer.
        /// </summary>
        /// <param name="obj">The obj.</param>
        public static void SetDoubleBuffer(object obj)
        {
            Type t = obj.GetType();
            MethodInfo m = t.GetMethod("SetStyle", BindingFlags.Public | BindingFlags.NonPublic |
                        BindingFlags.Instance);
            if (m != null)
            {
#if FRAMEWORK_VER_2x
                t.InvokeMember("SetStyle",
                        BindingFlags.Public | BindingFlags.NonPublic |
                        BindingFlags.Instance | BindingFlags.InvokeMethod, null, obj, new object[] { ControlStyles.OptimizedDoubleBuffer , true });

#else

                t.InvokeMember("SetStyle",
                        BindingFlags.Public | BindingFlags.NonPublic |
                        BindingFlags.Instance | BindingFlags.InvokeMethod, null, obj, new object[] { ControlStyles.AllPaintingInWmPaint | ControlStyles.DoubleBuffer | ControlStyles.UserPaint, true });

#endif

            }//End If
        }

		public static void Draw3DBox(Graphics g, int x, int y, int w, int h)
		{
			Pen p1 = new Pen(Color3D1);
			Pen p2 = new Pen(Color3D2);

			g.DrawRectangle(p2,x + 1, y + 1, w, h - 1);
			g.DrawRectangle(p1,x , y, w, h);
			//g.DrawLine(p2, x + 1, y + h,x + w + 1, y + h);
		}

		public static void Draw3DLine(Graphics g,int x,int y, int w, int direction /* = 0,V,H */ )
		{			
			Pen p1 = new Pen(Color3D1);
			Pen p2 = new Pen(Color3D2);

			if (direction == VERTICAL)
			{
				g.DrawLine(p1,x,y,x,y + w);;
				g.DrawLine(p2,x + 1,y,x + 1,y + w);
			}//End If
			else{
				g.DrawLine(p1,x,y,x + w,y);;
				g.DrawLine(p2,x,y + 1,x + w,y + 1);
			}
		}

		public static void SetXpStyle(System.Windows.Forms.Control.ControlCollection controls)
		{
			object [] arg = new object[]{System.Windows.Forms.FlatStyle.System};
			foreach (System.Windows.Forms.Control c in controls)
			{

				/*
				// If the control derives from ButtonBase, 
				//  set its FlatStyle property to FlatStyle.System.
				if(c.GetType().BaseType == typeof(System.Windows.Forms.ButtonBase))
				{
					((System.Windows.Forms.ButtonBase)c).FlatStyle = System.Windows.Forms.FlatStyle.System; 
				}
				*/
				System.Type t = c.GetType();
				PropertyInfo p = t.GetProperty("FlatStyle");
				
				/*
				if (t.GetProperty("FlatStyle") != null)
				{
					t.InvokeMember("FlatStyle",BindingFlags.DeclaredOnly | 
						BindingFlags.Public | BindingFlags.NonPublic | 
						BindingFlags.Instance| BindingFlags.SetProperty, null, c,arg);
				}//End If
  
				*/
				if (p != null)
				{
					p.SetValue(c,System.Windows.Forms.FlatStyle.System,null);
				}//End If
				// If the control holds other controls, iterate through them also.
				if(c.Controls.Count > 0)
				{
					SetXpStyle(c.Controls);
				}

			}//End Foreach
		}


		

	}
}
#endif